<!-- 日志管理 -->
<template>
    <div class="logs" v-loading="loading">
        <dy-table :elTable_Options="elTable_Options" @bottonHandle="bottonHandle" ref="table" />
    </div>
</template>

<script setup>
import { ref, reactive, toRefs, nextTick, onMounted } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import commonV from '@/common'
import api from '@/api'

//数据
let state = reactive({
    loading: false
})
let { loading } = toRefs(state)

//所有展示的数据
let allConfigList = [{
    label: "操作时间",
    prop: "operation_time",
    columType: 'time'
}, {
    label: "用户",
    prop: "operation_user_name",
    width: 110,
    columType: 'text'
}, {
    label: "事件",
    prop: "operation_event",
    columType: 'text'
}, {
    label: "操作对象",
    width: 140,
    prop: "operation_obj",
    columType: 'text'
}, {
    label: "是否存档",
    prop: "is_save",
    columType: 'select',
    commonVarrName: 'active_status'
}]

//配置项
let elTable_Options = ref({
    pagename: '日志管理',
    selection: false,
    allConfigList: allConfigList,
    eltableArr: allConfigList,
    getwayname: 'systemLogs',
    opbutton: [{
        label: '清除日志',
        dealway: 'deleteLogs',
        icon: 'Delete',
        type: "danger",
        keyV: "delete",
        disabled: false
    }, {
        label: "批量导出",
        dealway: "exportData",
        icon: 'Upload',
        type: "",
        keyV: "export",
        disabled: false
    }],
    //查询栏
    searchList: [{
        label: "时间段",
        key: "operation_time",
        labelStart: '开始时间',
        labelEnd: '结束时间',
        searchtype: 'timeQuantum'
    }, {
        label: "是否存档",
        key: "is_save",
        searchtype: 'select',
        options: commonV.statusOption.active_status
    }],
    importexport: {
        export_filename: '操作日志表.xls',
        export_api: 'logexportbatch'
    }
})

onMounted(() => {
    getTableData()
})

let table = ref(null)

//获取用户数据
let getTableData = () => {
    nextTick(() => {
        table.value.getTableData()
    })
}

//按钮点击
let bottonHandle = (wayname) => {
    if (wayname == 'deleteLogs') {
        //删除日志
        deleteLogs()
    }
}

//删除日志
let deleteLogs = () => {
    //获取选中项
    let selectArr = table.value.tableIntance.state.selection
    let filter = selectArr.filter(it => !it.is_save)
    if (!filter.length) {
        ElMessage({
            message: "选择中有未存档日志，请先导出保存",
            type: "warning"
        })
        return
    }
    let strTit = `确定删除所选${selectArr.length}项?`
    let ids = commonV.deveridarrry(selectArr)
    if (!selectArr.length) {
        strTit = '是否删除所有已存档日志?'
        ids = []
    }
    //删除全部
    ElMessageBox.confirm(
        strTit,
        '提示',
        {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning',
        }
    ).then(async () => {
        state.loading = true
        let res = await api.changeaxiosdata('logdeletebatch', 'post', { ids })
        if (res) {
            ElMessage({
                message: "删除成功!",
                type: "success"
            })
            getTableData()
        }
        state.loading = false
    }).catch(() => { })
}
</script>

<style lang="scss" scoped></style>